var http = require('http')
var url = require('url')
const YKoa = function () {
  this.server = null
  this.router = {}
}
YKoa.prototype.get = function (path, callback) {
  this.router[path] = callback
}
YKoa.prototype.listen = function (port, callback) {
  this.server = http.createServer((req, res) => {
    var pathname = url.parse(req.url).pathname
    for (const i in this.router) {
      if (i === `${pathname}`) {
        this.router[i](req, res)
      }
    }
  })
  this.server.listen(port)
  this.server.on('listening', () => {
    callback()
  })
}
module.exports = YKoa